package com.briup.corejava.day17;

import java.util.concurrent.*;

/**
 * 第三种线程的创建方法
 * Callable
 */
public class Test2 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        Callable<?> c1 = new Mc();
        Callable<?> c2 = new Mc2();
        FutureTask<?> f1 = new FutureTask<>(c1);
        FutureTask<?> f2 = new FutureTask<>(c2);
        int r1 = (Integer)f1.get();
        int r2 = (Integer)f2.get();

        // 使用线程池提交任务
//        ExecutorService es = Executors.newFixedThreadPool(2);
//        es.submit(c1);
//        es.submit(c2);
        System.out.println(r1+r2);

    }
}
class Mc implements Callable<Integer>{

    @Override
    public Integer call() throws Exception {
        int sum = 0;
        for(int i=1;i<50;i++){
            sum+=i;
        }
        return sum;
    }
}
class Mc2 implements Callable<Integer>{

    @Override
    public Integer call() throws Exception {
        int sum = 0;
        for(int i=50;i<=100;i++){
            sum+=i;
        }
        return sum;
    }
}

